using Sandia.MVCFramework.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Sandia.MVCFramework.ViewManager
{
    /// <summary>
    /// A delegate used for events associated with minimizing an IView.
    /// </summary>
    /// <param name="node">
    /// The ViewLayoutNode that was minimized.
    /// </param>
    public delegate void OnViewMinimized(ViewLayoutNode node);

    /// <summary>
    /// A wrapper class that adds a minimize button to a view.
    /// </summary>
    public partial class ViewWrapper : UserControl
    {
        private ViewLayoutNode node;

        /// <summary>
        /// Called when the minimize button is pressed.
        /// </summary>
        public event OnViewMinimized ViewMinimized;

        /// <summary>
        /// Constructor for the view wrapper.
        /// </summary>
        /// <param name="node">The ViewLayoutNode to wrap.</param>
        public ViewWrapper(
            ViewLayoutNode node)
        {
            // Check arguments.
            if (node == null)
            {
                LoggingTools.SendToLog(
                    "ViewWrapper.cs: Argument node is null.",
                    LoggingCategories.ERROR,
                    100);
                return;
            }

            InitializeComponent();

            this.node = node;
            this.Dock = DockStyle.Fill;
            if (typeof(Control).IsInstanceOfType(node.View))
            {
                this.mainPanel.Controls.Add((Control)node.View);
            }
            this.viewImageButton.Image = node.View.ViewImage;
            this.viewImageButton.Text = node.View.Name;

            toolStrip1.Visible = node.View.ToolBarVisible;
        }

        /// <summary>
        /// The ViewLayoutNode that this wraps.
        /// </summary>
        public ViewLayoutNode Node
        {
            get { return this.node; }
        }

        /// <summary>
        /// Called when the minimize button is clicked.
        /// </summary>
        /// <param name="sender">The button that sent the message.</param>
        /// <param name="e">The event arguments.</param>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (this.ViewMinimized != null)
            {
                this.ViewMinimized(this.node);
            }
        }
    }
}
